﻿@model List<MengRan.Models.index.mens>
@{
    Layout = null;
}
<html>
<head>
    <meta charset="utf-8">
    <title>示例演示</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 注意：项目正式环境请勿引用该地址 -->
    <link rel="stylesheet" href="~/lib/layui/css/layui.css">
</head>
<body>

    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
        <legend>模块管理</legend>
    </fieldset>
    <div class="layui-btn-container">
        <button type="button" class="layui-btn layui-btn-sm" lay-demo="getChecked">获取选中节点数据</button>
        <button type="button" class="layui-btn layui-btn-sm" lay-demo="setChecked">勾选指定节点</button>
        <button type="button" class="layui-btn layui-btn-sm" lay-demo="reload">重载实例</button>
    </div>

    <div id="test12" class="demo-tree-more"></div>


    <!-- 注意：项目正式环境请勿引用该地址 -->
    <script src="~/lib/layui/layui.js" charset="utf-8"></script>
    <script src="~/lib/jquery/dist/jquery.js"></script>
    <script>
        layui.use(['tree', 'util'], function () {
            var tree = layui.tree
                , layer = layui.layer
                , util = layui.util
            //模拟数据
            $.post("/api/liuyan/menss", function (retsy) {
                alert(retsy[0].zhuci);
                var tee = [];
                for (var i = 0; i <= retsy.length; i++) {
                    var a = retsy[i].zhuci
                    if (a == 0) {
                        var parent = [];
                        parent.id = retsy[i].id;
                        parent.title = retsy[i].dataname;
                        parent.children = [];
                        for (var k = 0; k < retsy.length; k++) {
                            if (retsy[k].dataname == retsy[i].dataname) {
                                var chidren = [];
                                chidren.id = retsy[k].id;
                                chidren.title = retsy[k].dataname;
                                parent.children.push(chidren);
                            }
                        }
                        tee.push(parent);
                    }
                }
            })
           

            //按钮事件
            util.event('lay-demo', {
                getChecked: function (othis) {
                    var checkedData = tree.getChecked('demoId1'); //获取选中节点的数据

                    layer.alert(JSON.stringify(checkedData), { shade: 0 });
                    console.log(checkedData);
                }
                , setChecked: function () {
                    tree.setChecked('demoId1', [12, 16]); //勾选指定节点
                }
                , reload: function () {
                    //重载实例
                    tree.reload('demoId1', {

                    });

                }
            });



            //点击节点新窗口跳转
            tree.render({
                elem: '#test5'
                , data: data
                , isJump: true  //link 为参数匹配
            });
        });
    </script>

</body>
</html>